package icu.d4peng.basic.http.feign.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import icu.d4peng.basic.http.feign.SpringQueryMap;
import feign.MethodMetadata;

import icu.d4peng.basic.http.feign.AnnotatedParameterProcessor;

/**
 * @author d4peng d4peng@qq.com
 * @date 2023-11-26 15:36:16
 */

public class QueryMapParameterProcessor implements AnnotatedParameterProcessor {

	private static final Class<SpringQueryMap> ANNOTATION = SpringQueryMap.class;

	@Override
	public Class<? extends Annotation> getAnnotationType() {
		return ANNOTATION;
	}

	@Override
	public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) {
		int paramIndex = context.getParameterIndex();
		MethodMetadata metadata = context.getMethodMetadata();
		if (metadata.queryMapIndex() == null) {
			metadata.queryMapIndex(paramIndex);
		}
		return true;
	}

}
